<?php

require_once 'Response.php';
require_once 'DB.php';

$pdo = DB::getInstance()->connect();
$stmt = $pdo->query("SELECT * FROM `type`"); //返回一个PDOStatement对象
$type = $stmt->fetchAll(); //获取所有
$res = [];

foreach($type as $item) {
    $stmt = $pdo->query("SELECT * FROM `goods` WHERE type_id = {$item['id']}"); //返回一个PDOStatement对象
    $goods = $stmt->fetchAll(); //获取所有

    $item['content'] = $goods;
    $res[] = $item;
}

Response::json(200, '获取成功！', $res);